package com.neo.subscribe.stamp.service;

import com.neo.subscribe.stamp.dto.Stamp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 近期热门
 */
@Slf4j
@Service
public class RecentHotResponseProcess extends AbstractResponseProcess {

    @Autowired
    private StampService stampService;

    private final BigDecimal RATE = new BigDecimal("100");

    @Override
    public int process(String responseText) {
        List<Stamp> stamps = processStampPageData(responseText);
        if (CollectionUtils.isEmpty(stamps)) {
            return 0;
        }

        stamps.forEach(i -> i.setMinPrice(i.getMinPrice().divide(RATE, 2, RoundingMode.HALF_DOWN)));
        return stampService.saveStampList(stamps);
    }
}
